package com.nbufe.domain.dto.process;

import com.alibaba.fastjson.JSON;
import com.nbufe.domain.entity.EmissionOrigin;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author luzhiheng
 * @Date 2023/12/28 10:39
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class QueryEmissionOriginDetailVo {

    /**
     * 排放源id
     */
    @NotNull(message = "请选择能源物质")
    private Long emissionOriginId;

    /**
     * 能源材料名称
     */
    @NotEmpty(message = "名称不能为空")
    private String name;

    /**
     * 生产阶段
     */
    @NotNull
    private List<StageVo> stageVoList;

    public QueryEmissionOriginDetailVo(EmissionOrigin emissionOrigin) {
        this.emissionOriginId = emissionOrigin.getId();
        this.name = emissionOrigin.getName();
        List<Integer> idList = JSON.parseArray(emissionOrigin.getProduceStage(), Integer.class);
        this.stageVoList = idList.stream().map(StageVo::new).collect(Collectors.toList());
    }
}
